/*
 * Copyright &copy; 2011-2020 lnint Inc. All right reserved.
 * 
 * 修改信息：【与SVN提交信息一致】
 * A: 新增类 中文姓名 2014-12-17 12:02:25
 */
package com.lnint.jess.generator.entity;


import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Where;

import com.google.common.collect.Lists;
import com.lnint.jess.common.annotation.Comment;
import com.lnint.jess.common.persistence.IdEntity;
import com.lnint.jess.common.utils.StringUtils;

/**
 * <P>场景 基本 信息</P>
 * 
 * @version 1.0
 * @author 王磊 2015-03-19 12:02:25 11
 * @since JDK 1.6
 */
@Entity
@Table(name = "gen_scene")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class GenScene extends IdEntity<GenScene> {
	
	private static final long serialVersionUID = 1L;
	@Comment(name ="场景类型",dictType = "sys_gen_scene_type")
	private String sceneType; 	
	@Comment(name ="主表名称")
	private String name; 	
	@Comment(name ="描述")
	private String comments;
	@Comment(name ="主表实体类名称")
	private String className;		
	@Comment(name ="从表名称")
	private String subname; 	
	@Comment(name ="从表实体类名称")
	private String subclassName;
	@Comment(name ="主表列表每页记录数")
	private Integer pageSize;
	@Comment(name ="从表列表每页记录数")
	private Integer subpageSize;
	@Comment(name ="主表form每行记录数")
	private Integer formColumn;
	@Comment(name ="从表form每行记录数")
	private Integer subformColumn;
	
	@Comment(name ="主表 表物理字段列")
	private List<GenSceneColumn> columnList = Lists.newArrayList();	
	@Comment(name ="从表 表物理字段列")
	private List<GenSceneColumn> subColumnList = Lists.newArrayList();	
	@Comment(name ="主表 级联关系字段")
	private List<GenSceneRelateColumn> relatecolumnList = Lists.newArrayList();	
	@Comment(name ="从表 级联关系字段")
	private List<GenSceneRelateColumn> subRelatecolumnList = Lists.newArrayList();
	
	
	public GenScene() {
		super();
	}

	public GenScene(String id){
		super();
		this.id = id;
	}
	@OneToMany(mappedBy = "genScene", fetch = FetchType.EAGER)
    @Where(clause = "del_flag='" + DEL_FLAG_NORMAL + "' and is_subtable='0' ")
    @OrderBy(value = "id")
    @Fetch(FetchMode.SUBSELECT)
    @NotFound(action = NotFoundAction.IGNORE)
	public List<GenSceneRelateColumn> getRelatecolumnList() {
		return relatecolumnList;
	}

	public void setRelatecolumnList(List<GenSceneRelateColumn> relatecolumnList) {
		this.relatecolumnList = relatecolumnList;
	}
	@OneToMany(mappedBy = "genScene", fetch = FetchType.EAGER)
    @Where(clause = "del_flag='" + DEL_FLAG_NORMAL + "' and is_subtable='1' ")
    @OrderBy(value = "id")
    @Fetch(FetchMode.SUBSELECT)
    @NotFound(action = NotFoundAction.IGNORE)
	public List<GenSceneRelateColumn> getSubRelatecolumnList() {
		return subRelatecolumnList;
	}

	public void setSubRelatecolumnList(
			List<GenSceneRelateColumn> subRelatecolumnList) {
		this.subRelatecolumnList = subRelatecolumnList;
	}



	/**
	 * @return the sceneType
	 */
	public String getSceneType() {
		return sceneType;
	}

	/**
	 * @param sceneType the sceneType to set
	 */
	public void setSceneType(String sceneType) {
		this.sceneType = sceneType;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the comments
	 */
	public String getComments() {
		return comments;
	}

	/**
	 * @param comments the comments to set
	 */
	public void setComments(String comments) {
		this.comments = comments;
	}

	/**
	 * @return the className
	 */
	public String getClassName() {
		return className;
	}

	/**
	 * @param className the className to set
	 */
	public void setClassName(String className) {
		this.className = className;
	}

	/**
	 * @return the subname
	 */
	public String getSubname() {
		return subname;
	}

	/**
	 * @param subname the subname to set
	 */
	public void setSubname(String subname) {
		this.subname = subname;
	}

	/**
	 * @return the subclassName
	 */
	public String getSubclassName() {
		return subclassName;
	}

	/**
	 * @param subclassName the subclassName to set
	 */
	public void setSubclassName(String subclassName) {
		this.subclassName = subclassName;
	}

	/**
	 * @return the pageSize
	 */
	public Integer getPageSize() {
		return pageSize;
	}

	/**
	 * @param pageSize the pageSize to set
	 */
	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	/**
	 * @return the subpageSize
	 */
	public Integer getSubpageSize() {
		return subpageSize;
	}

	/**
	 * @param subpageSize the subpageSize to set
	 */
	public void setSubpageSize(Integer subpageSize) {
		this.subpageSize = subpageSize;
	}

	/**
	 * @return the formColumn
	 */
	public Integer getFormColumn() {
		return formColumn;
	}

	/**
	 * @param formColumn the formColumn to set
	 */
	public void setFormColumn(Integer formColumn) {
		this.formColumn = formColumn;
	}

	/**
	 * @return the subformColumn
	 */
	public Integer getSubformColumn() {
		return subformColumn;
	}

	/**
	 * @param subformColumn the subformColumn to set
	 */
	public void setSubformColumn(Integer subformColumn) {
		this.subformColumn = subformColumn;
	}

	/**
	 * @return the columnList
	 */
	@OneToMany(mappedBy = "genSceneId", fetch = FetchType.EAGER)
    @Where(clause = "del_flag='" + DEL_FLAG_NORMAL + "' and is_subtable='0'")
    @OrderBy(value = "id")
    @Fetch(FetchMode.SUBSELECT)
    @NotFound(action = NotFoundAction.IGNORE)
	public List<GenSceneColumn> getColumnList() {
		return columnList;
	}

	/**
	 * @param columnList the columnList to set
	 */
	public void setColumnList(List<GenSceneColumn> columnList) {
		this.columnList = columnList;
	}

	@OneToMany(mappedBy = "genSceneId", fetch = FetchType.EAGER)
    @Where(clause = "del_flag='" + DEL_FLAG_NORMAL + "' and is_subtable='1' ")
    @OrderBy(value = "id")
    @Fetch(FetchMode.SUBSELECT)
    @NotFound(action = NotFoundAction.IGNORE)
	public List<GenSceneColumn> getSubColumnList() {
		return subColumnList;
	}

	/**
	 * @param subColumnList the subColumnList to set
	 */
	public void setSubColumnList(List<GenSceneColumn> subColumnList) {
		this.subColumnList = subColumnList;
	}

	/**
	 * 获取导入依赖包字符串
	 * @return
	 */
	@Transient
	public List<String> getImportList(){
		List<String> importList = Lists.newArrayList(); // 引用列表
		for (GenSceneColumn column : columnList){
			if (column.getIsNotBaseField() || ("1".equals(column.getIsQuery()) && ("create_date".equals(column.getJavaField()) || "update_date".equals(column.getJavaField())))){
				// 导入类型依赖包， 如果类型中包含“.”，则需要导入引用。
				if (!importList.contains("java.util.Date")){
					importList.add("java.util.Date");
				}
			}
			if (column.getIsNotBaseField()){
				// 导入JSR303、Json等依赖包
				for (String ann : column.getAnnotationList()){
					if (!importList.contains(StringUtils.substringBeforeLast(ann, "("))){
						importList.add(StringUtils.substringBeforeLast(ann, "("));
					}
				}
			}
		}
		return importList;
	}

	
}


